package cn.edu.njpi.utils;

import cn.edu.njpi.model.TPermssion;
import cn.edu.njpi.service.TPermssionService;
import cn.edu.njpi.service.impl.TPermssionServiceImpl;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author 朱宗辉
 * @version V1.0
 * @Package cn.edu.njpi.utils
 * @date 2022/4/19 7:20 PM
 */
public class InformUtils {
    private static TPermssionService tPermssionService = SpringContextUtils.getBeanByClass(TPermssionServiceImpl.class);

    public static String title = "操行分管理系统";
    public static ExpiringMap<Object, Object> map = ExpiringMap.builder().expiration(2, TimeUnit.HOURS).variableExpiration().expirationPolicy(ExpirationPolicy.CREATED).build();
    private static Map<Integer, String> userPermssionMap = new HashMap<>();

    public static String getPermssionName(int userPermssionId) {
        if (userPermssionMap.size() == 0) {
            List<TPermssion> tPermssionList = tPermssionService.getAllPermssion();
            for (TPermssion tPermssion : tPermssionList) {
                userPermssionMap.put(tPermssion.getUserPermssionId(), tPermssion.getUserPermssionName());
            }
        }
        return userPermssionMap.get(userPermssionId);
    }
}
